package kin.bean.security;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;


@Embeddable
public class AclId implements Serializable{
	
    public AclId(){}
    
  /*  public AclId(Module module, String principalType,int principalId){
    	this.module=module;
    	this.principalId=principalId;
    	this.
    }
    */
    @Column(name = "principalId")
	private int principalId;
    @Column(name = "principalType")
	private String principalType;
  
	public String getPrincipalType() {
		return principalType;
	}

    
	@ManyToOne(cascade={CascadeType.MERGE},fetch=FetchType.EAGER,optional=true)
	private Module module;
	
	public int getPrincipalId() {
		return principalId;
	}
	public void setPrincipalId(int principalId) {
		this.principalId = principalId;
	}
	public void setPrincipalType(String principalType) {
		this.principalType = principalType;
	}
	public Module getModule() {
		return module;
	}
	public void setModule(Module module) {
		this.module = module;
	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((module == null) ? 0 : module.hashCode());
		result = prime * result
				+ ((principalId == 0) ? 0 : principalId);
		result = prime * result
				+ ((principalType == null) ? 0 : principalType.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AclId other = (AclId) obj;
		if (module == null) {
			if (other.module != null)
				return false;
		} else if (!module.equals(other.module))
			return false;
		if (principalId == 0) {
			if (other.principalId != 0)
				return false;
		} else if (principalId!=other.principalId)
			return false;
		if (principalType == null) {
			if (other.principalType != null)
				return false;
		} else if (!principalType.equals(other.principalType))
			return false;
		return true;
	}

}
